package com.google.code.coma.rmi;

import com.google.code.coma.domain.Order;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 */
public class OrderSelector implements EntrySelector<Order> {
    private Order idTemplate;

    @Override
    public List<Order> selectEntries(List<Order> allEntries) throws SelectionException {
        if (idTemplate != null) {
            selectByIdTemplate(allEntries);
        }

        return new ArrayList<Order>();
    }

    private List<Order> selectByIdTemplate(List<Order> allEntries) throws SelectionException {
        if (idTemplate != null) {
            for (Order order : allEntries) {
                if (order.getId().equals(idTemplate.getId())) {
                    return Collections.singletonList(order);
                }
            }

        }

        throw new SelectionException();
    }
}
